﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{

    class ISYC_306_03
    {
        //ISYC 306-03-带可转位刀片非中心切削扩孔钻
        public static void ISYC_306_03_g(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["lpr"]);
            double scale = Convert.ToDouble(data["scale"]);
         //   double sl_ = 45;
         //   double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dc = 20 * scale;
            double df = 35 * scale;
            double lu = 45 * scale;
            double dcintf = 5 * scale;
            double dconms = 30 * scale;
            double lcf = 61.11 * scale;
            double lpr = 69.45 * scale;
            double ls = 50 * scale;
            double sig = 150;
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double oal = ls + lpr;
            double lta = oal - pl;
            */
            double dc = Convert.ToDouble(data["dc"]) * scale;
            double df = Convert.ToDouble(data["df"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double dcintf = Convert.ToDouble(data["dcintf"]) * scale;
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double lcf = Convert.ToDouble(data["lcf"]) * scale;
            double lpr = Convert.ToDouble(data["lpr"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double sig = Convert.ToDouble(data["sig"]);
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double oal = ls + lpr;
            double lta = oal - pl;
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0, 0, oal + 5);
            Vector2 p1 = fun.Polar(p0, pi / 2, dcintf /2.0+(dc / 2.0 - dcintf / 2.0)/2.0);
            Vector2 p2 = fun.mirrorpoint(p1, p0_1, p0_2);
            Vector2 p3 = fun.Polar(p1, sig_/2, pl / Math.Cos(sig_ / 2));
            Vector2 p4 = fun.Polar(p3, fun.CalAngle(p3, p1) + pi / 2, fun.CalDistance(p3, p1));
            Vector2 p5 = fun.Polar(p4, fun.CalAngle(p4, p3) + sig_, fun.CalDistance(p3, p1));
            Vector2 p6 = fun.Polar(p5, fun.CalAngle(p5, p4) + pi / 2, fun.CalDistance(p3, p1));
            Vector2 p7 = fun.Polar(p6, fun.CalAngle(p6, p5) + sig_, fun.CalDistance(p3, p1));
            Vector2 p8 = fun.mirrorpoint(p3, p0_1, p0_2);
            Vector2 p9 = fun.mirrorpoint(p7, p0_1, p0_2);
            Vector2 p10 = fun.Polar(p8, 0, lcf / 200.0);
            Vector2 p11_1 = fun.Polar(p2, 0, oal);
            Vector2 p11_2 = fun.Polar(p10, fun.CalAngle(p8, p2), oal);
            Vector2 p11 = fun.Inters(p10, p11_2, p2, p11_1);
            Vector2 p12_1 = fun.Polar(p0, pi / 2, dcintf / 4.0);
            Vector2 p12_2 = fun.Polar(p12_1, 0, oal);
            Vector2 p12_3 = fun.Polar(p11, fun.CalAngle(p2, p9), oal);
            Vector2 p12 = fun.Inters(p11, p12_3, p12_1, p12_2);
            Vector2 p13_0 = fun.Polar(p12, fun.CalAngle(p7, p1), oal);
            Vector2 p13 = fun.Inters(p12, p13_0, p7, p6);
            Vector2 p14 = fun.Polar(p11, fun.CalAngle(p13, p6), fun.CalDistance(p13, p6) / 2.0);
            Vector2 p15 = fun.Polar(p8, 0, lcf / 6.0) ;
            Vector2 p16_1 = fun.Polar(p15, pi / 2, oal);
            Vector2 p16_2 = fun.Polar(fun .Polar (p7,pi/-2,fun .CalDistance (p7,p12)/2.0), 0, oal);
            Vector2 p16 = fun.Inters(p7, p16_2, p16_1, p15);
            Vector2 arc1_1 = fun.Polar(fun.Polar(p7, pi / -2, fun.CalDistance(p7, p12) / 2.0), pi / -2, 0.1*scale );
            Vector2 arc1_2 = fun.Polar(arc1_1, 0, oal);
            Arc arc1 = fun.DrawArc5(p12, new Line(arc1_1, arc1_2), p16);
            Vector2 p17_0 = fun.Polar(p14, pi / 2 - 10 * pi / 180, oal);
            Vector2 p17 = fun.Inters1(p14, p17_0, arc1, 0);
            Vector2 arc2_1 = fun.Polar(p17, 0, 0.01 * scale);
            Vector2 arc2_2 = fun.Polar(arc2_1 , pi / -2+0.001*pi/180, oal);
            Arc arc2 = fun.DrawArc5(p14, new Line(arc2_1, arc2_2), p17);
            Vector2 p18_0 = fun.Polar(p9, 0, oal);
            Vector2 p18 = fun.Inters(p9, p18_0, p12, p11);
            Vector2 p19 = fun.Polar(p3, fun.CalAngle(p3, p4), fun.CalDistance(p3, p4) / 3.0);
            Vector2 p20_0=fun .Polar (p19,0,oal);
            Vector2 p20 = fun.Inters(p19, p20_0, p15, p16_1);
            Vector2 p21 = fun.Polar(p15, pi / 4, dc / 20.0);
            Vector2 p22 = fun.Polar(p20, pi / -4, fun.CalDistance(p15, p21));
            Vector2 p23 = new Vector2(lpr , 0);
            Vector2 p24 = fun.Polar(p23, pi / 2, df / 2.0);
            Vector2 p25 = fun.mirrorpoint(p24, p0_1, p0_2);
            Vector2 p26 = fun.Polar(p24, pi, lpr * (5.25 / 125.4));
            Vector2 p27 = fun.mirrorpoint(p26, p0_1, p0_2);
            Vector2 p28_0 = new Vector2(lcf, 0);
            Vector2 p28 = new Vector2(lcf, p26.Y - (p26.X - p28_0.X));
            Vector2 p29 = fun.mirrorpoint(p28, p0_1, p0_2);
            Vector2 arc3_1 = fun.Polar(p14, 0, 0.01 * scale);
            Vector2 arc3_2 = fun.Polar(arc3_1, pi / -2, oal);
            Arc arc3 = fun.DrawArc5(p10, new Line(arc3_2, arc3_1), p14);
            Vector2 arc4_1 = fun.Polar(p28, pi / 2, 0.01 * scale);
            Vector2 arc4_2 = fun.Polar(arc4_1, pi, oal);
            Arc arc4 = fun.DrawArc5(p28, new Line(arc4_1, arc4_2), p16);
            Vector2 p30_0 = fun.Polar(p22, -1 * pi / 180, oal);
            Vector2 p30 = fun.Inters1(p22, p30_0, arc4, 0);
            Vector2 arc5_1 = fun.Polar(p22, pi / 2, 0.01 * scale);
            Vector2 arc5_2 = fun.Polar(arc5_1, 0, oal);
            Arc arc5 = fun.DrawArc5(p30, new Line(arc5_1, arc5_2), p22);
            Vector2 p31_1 = fun.Polar(p22, pi / -4, oal);
            Vector2 p31 = fun.Inters1(p22, p31_1, arc4, 0);
            Vector2 arc6_1 = fun.Polar(p22, pi + pi / 4, 0.1 * scale);
            Vector2 arc6_2 = fun.Polar(arc6_1, pi / -4, oal);
            Arc arc6 = fun.DrawArc5(p22, new Line(arc6_1, arc6_2), p31);
            Vector2 p32_0  = fun.Polar(p14, 0, oal );
            Vector2 p32 = fun.Polar(p14, 0, lu);
            Vector2 arc7_1 = fun.Polar(p29, 0, 0.1 * scale);
            Vector2 arc7_2 = fun.Polar(arc7_1, 125 * pi / 180, oal);
            Arc arc7 = fun.DrawArc5(p29, new Line(arc7_1  , arc7_2), p32);
            Vector2 arc8_1 = fun.Polar(p21, pi / -2, 0.1 * scale);
            Vector2 arc8_2 = fun.Polar(arc8_1, 0, oal);
            Arc arc8 = fun.DrawArc5(p21, new Line(arc8_1, arc8_2), p32);
            Vector2 p33_0 = fun.Polar(p28, 0, oal);
            Vector2 p33 = fun.Inters(p28, p33_0, p26, p27);
            Vector2 p34 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p35 = fun.Inters(p28, p33_0, p24, p25);
            Vector2 p36 = fun.mirrorpoint(p35, p0_1, p0_2);
            Vector2 arc9_1 = fun.Polar(p28, 0, (p26.X - p28.X) / 3.0);
            Vector2 arc9_2 = fun.Polar(arc9_1, pi / -2+0.01*pi/180, oal);
            Arc arc9 = fun.DrawArc5(p33, new Line(arc9_1, arc9_2), p34);
            Vector2 p37_0 = fun.Polar(p29, pi - 10 * pi / 180, oal);
            Vector2 p37 = fun.Inters1(p29, p37_0, arc8, 1);
            //非切削部分
            Vector2 p38 = fun.Polar(p0, 0, oal);
            Vector2 p39 = fun.Polar(p38, pi / 2, dconms / 2.0 - dconms / 20.0);
            Vector2 p40 = fun.Polar(p39, pi - pi / 4, ( dconms / 20.0) / Math.Sqrt(2));
            Vector2 p41 = fun.Polar(p40, pi, ls - (p39.X  - p40.X ) - (( dconms / 20.0) * 1.5));
            Vector2 p42 = fun.Polar(p41, pi / -2, ( dconms / 30.0) / 2.0);
            Vector2 p43_0 = fun.Polar(p42, pi, oal);
            Vector2 p43 = fun.Inters(p24, p25, p42, p43_0);
            Vector2 p44 = fun.mirrorpoint(p39, p0_1, p0_2);
            Vector2 p45 = fun.mirrorpoint(p40, p0_1, p0_2);
            Vector2 p46 = fun.mirrorpoint(p41, p0_1, p0_2);
            Vector2 p47 = fun.mirrorpoint(p42, p0_1, p0_2);
            Vector2 p48 = fun.mirrorpoint(p43, p0_1, p0_2);
            Vector2 p49 = fun.Polar(p0, pi, dconms * 2);
            Vector2 p50 = fun.Polar(p49, pi / 2, dc / 2.0);
            Vector2 p51 = fun.Polar(p50, pi / 2, dc / 4.0);
            Vector2 p52 = fun.Polar(p51, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p53 = fun.Polar(p52, -10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p54= fun.Polar(p53, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p55= fun.Polar(p54, -10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p56= fun.Polar(p55, 10 * pi / 180, (dconms / 2.0 / 5.0) / Math.Cos(10 * pi / 180));
            Vector2 p57 = fun.Polar(p56, pi / -2, fun.CalDistance(p50, p51)) ;
            Vector2 p58 = fun.mirrorpoint(p50, p0_1, p0_2);
            Vector2 p59= fun.mirrorpoint(p51, p0_1, p0_2);
            Vector2 p60= fun.mirrorpoint(p52, p0_1, p0_2);
            Vector2 p61 = fun.mirrorpoint(p53, p0_1, p0_2);
            Vector2 p62= fun.mirrorpoint(p54, p0_1, p0_2);
            Vector2 p63= fun.mirrorpoint(p55, p0_1, p0_2); 
            Vector2 p64= fun.mirrorpoint(p56, p0_1, p0_2);
            Vector2 p65= fun.mirrorpoint(p57, p0_1, p0_2);
            var polyline4 = Pus.AddPointsToLwPolyLine(p50, p51, p52, p53, p54, p55, p56, p57, p50);
            var polyline5 = Pus.AddPointsToLwPolyLine(p58, p59, p60, p61, p62, p63, p64, p65, p58);
            for (double n=1;n<3;n++)
            {
                String[] htypen = new String[100];
                Line[] hlinen = new Line[100];
                Arc[] harcn = new Arc[100];
                var polylinen=polyline4 ;
                if ( n==1)
                {
                     polylinen = polyline4;
                }
                else
                {
                     polylinen = polyline5;
                }
                int hnumstn = polylinen.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumstn; i++)
                {
                    htypen[i] = polylinen.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htypen[i] == "Line")
                    {
                        hlinen[i] = (Line)polylinen.Explode()[i];
                    }
                    if (htypen[i] == "Arc")
                    {
                        harcn[i] = (Arc)polylinen.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htypen, hnumstn, 135, 10*scale , hlinen, harcn, hatching);
            }
            var polyline1 = Pus.AddPointsToLwPolyLine(p13, p7, p1, p3,p19,p20,p22,p20,p19, p4, p5, p6, p13, p12, p11,
            p14, p11, p10, p15,p21,p15, p16, p15, p10, p8, p2, p9, p18
            );
            var polyline2 = Pus.AddPointsToLwPolyLine(p28, p26, p24,p35,p33,p26,p24, p25, p27,p34,p36,p25,p27, p29,p37 );
            polyline2.Vertexes[0].Bulge = Math.Tan((pi/2) / 4);
            polyline2.Vertexes[12].Bulge = Math.Tan((pi / 2) / 4);
            var polyline3 = Pus.AddPointsToLwPolyLine(p43, p42, p47, p42, p41, p40, p45, p40, p39, p44, p45, p46, p47, p48);
           /* dxf.AddEntity(new EntityObject[] { polyline1 ,polyline2  ,polyline3 ,polyline4 ,polyline5 
            ,arc1 ,arc2 ,arc3 ,arc4,arc5,arc6 ,arc7,arc8,arc9 
            });*/
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            fun.drawBArc(dxf, arc3, 0.5, contour);
            fun.drawBArc(dxf, arc4, 0.5, contour);
            fun.drawBArc(dxf, arc5, 0.5, contour);
            fun.drawBArc(dxf, arc6, 0.5, contour);
            fun.drawBArc(dxf, arc7, 0.5, contour);
            fun.drawBArc(dxf, arc8, 0.5, contour);
            fun.drawBArc(dxf, arc9, 0.5, contour);
            //标注
            Vector2 v1 = fun.Polar(p41, 0, fun.CalDistance(p41, p40) / 8.0);
            Vector2 v2 = fun.Polar(p26, pi, lpr - lcf);
            Vector2 v3 = fun.Polar(p27, pi, lpr - lcf);
            Vector2 v4 = fun.Polar(p3, pi - pi / 4, 0.5 * 1.7 * scale);
            Vector2 v5 = fun.Polar(p0, pi + pi / 4, 0.5 * 1.7 * scale);
            Vector2 v6 = fun.Polar(v5, pi + pi / 4, dc / 1.5);
            Vector2 v7 = fun.Polar(p23, pi / -4, 0.5 * 1.7 * scale);
            Vector2 v8 = fun.Polar(v7, pi / -4, dconms);
            Vector2 v9 = fun.Polar(p3, pi - pi / 6, dc * 2);
            fun.dimrot1(dxf, p0, p32, 180, dc+p32.Y , 2, 1.2 * scale, 1.6 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p0, p29, 180, dc*1.5 + p29.Y, 2, 1.2 * scale, 1.6 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p0, p25, 180, dc*2 + p25.Y, 2, 1.2 * scale, 1.6 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p44, p25, 180, dc*2 + p25.Y+p44.Y/2.0 , 2, 1.2 * scale, 1.6 * scale, 0.9, "LS", "", "");
            fun.dimrot1(dxf, p44, p0, 180, dc*2.5+(p25.Y ), 2, 1.2 * scale, 1.6 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p3, p8, 90, dc*1.5, 2, 1.2 * scale, 1.6 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p7, p9, 90, dc/1.2, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCINTF", "", "");
            fun.dimrot1(dxf, p24, p3 ,0, dc*1.5-(p24.Y-p3.Y )/2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LTA,LF", "", "");
            fun.dimrot1(dxf, p0, p3, 0, dc*1.5-p3.Y/2.0 , 2, 1.2 * scale, 1.6 * scale, 0.9, "PL", "", "");
            fun.dimrot1(dxf, p40, p45, -90, dc , 2, 1.2 * scale, 1.6 * scale, 0.9, "DCONMS", "", "");
            fun.dimrot1(dxf, p50, p58, -90, dc/10.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "PHD", "", "");
            fun.jdbz2(dxf, new Line(p8, p2), new Line(p3, p1), dc, 1.2 * scale, 1.6 * scale, 0.9, "SIG", "", "");
            fun.Singlelinearrow(dxf, "CCMS", v1, 70, fun.Polar(v1, 70 * pi / 180, dc / 2.0), fun.Polar(v1, 70 * pi / 180, dc), 1.2 * scale, 1.6 * scale);
            fun.Singlelinearrow(dxf, "FDP", v9, 180, fun.Polar(v9, 0, dc / 6.0), fun.Polar(v9, 0, dc / 3.0), 1.2 * scale, 1.6 * scale);
            fun.Singlelinearrow(dxf, "DF", v2, 90, fun.Polar(v2, 90 * pi / 180, dc / 6.0), fun.Polar(v2, 90 * pi / 180, dc/3.0), 1.2 * scale, 1.6 * scale);
            fun.Singlelinearrow(dxf, "", v3, -90, fun.Polar(v3, -90 * pi / 180, dc / 10.0), fun.Polar(v3, -90 * pi / 180, dc/5.0), 1.2 * scale, 1.6 * scale);
            Line linev1 = new Line(p26, v2);
            Line linev2 = new Line(p27, v3);
            Line linev3 = new Line(v4, fun.Polar(p3, pi - pi / 4, dconms / 2.0));
            Line linev4 = new Line(v5, v6 );
            Line linev5 = new Line(v7, v8);
            Line linev6 = new Line(p0_1 , p0_2 );
            linev6.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev6.Layer = centre;//Layer指图层
            linev6.LinetypeScale = 5 * scale ;//指线性比例
            linev6.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev6); //提取
            Text txt1 = new Text("CRP", fun.Polar(p3, pi - pi / 4, dconms / 2.0), 1.6 * scale, 0);
            Text txt2 = new Text("CIP", fun.Polar(v6, pi / -2, 1.2 * scale), 1.2 * scale, 0);
            Text txt3 = new Text("PCS,MCS", fun.Polar(v8, pi / -2, 1.2 * scale), 1.2 * scale, 0);
            Text txt4 = new Text("ISYC=306_03", fun.Polar(p41 , pi / 2, dc  * 2), 1.2 * scale, 0);
            Circle circle1 = new Circle(p3 , 1.7 * 0.5 * scale);
            Circle circle2 = new Circle(p0, 1.7 * 0.5 * scale); 
            Circle circle3 = new Circle(p23, 1.7 * 0.5 * scale);
            fun.Axis(dxf, fun.Polar(p38, -70*pi/180, dc * 2), 0, -90, "Z", "X", "Y", 0.5 * scale, 1.2 * scale, 0);
            fun.Axis(dxf, p0 , 0, -90, "", "", "", 0.5 * scale, 1.2 * scale, 0);
            fun.Axis(dxf, p23, 0, -90, "", "", "", 0.5 * scale, 1.2 * scale, 0);
            dxf.AddEntity(new EntityObject[] { linev1, linev2 ,linev3 ,linev4 ,linev5 
            ,txt1,txt2 ,txt3 ,txt4 
            ,circle1 ,circle2,circle3  
            });
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        //ISYC 306-03-带可转位刀片非中心切削扩孔钻
        public static void ISYC_306_03_j(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double sl_ = Convert.ToDouble(data["lpr"]);
            double scale = Convert.ToDouble(data["scale"]);
            // double sl_ = 45;
            // double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }/*
            double dc = 20 * scale;
            double df = 35 * scale;
            double lu = 45 * scale;
            double dcintf = 5 * scale;
            double dconms = 30 * scale;
            double lcf = 61.11 * scale;
            double lpr = 69.45 * scale;
            double ls = 50 * scale;
            double sig = 150;
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double oal = ls + lpr;
            double lta = oal - pl;
            */
            double dc = Convert.ToDouble(data["dc"]) * scale;
            double df = Convert.ToDouble(data["df"]) * scale;
            double lu = Convert.ToDouble(data["lu"]) * scale;
            double dcintf = Convert.ToDouble(data["dcintf"]) * scale;
            double dconms = Convert.ToDouble(data["dconms"]) * scale;
            double lcf = Convert.ToDouble(data["lcf"]) * scale;
            double lpr = Convert.ToDouble(data["lpr"]) * scale;
            double ls = Convert.ToDouble(data["ls"]) * scale;
            double sig = Convert.ToDouble(data["sig"]);
            double sig_ = sig * pi / 180;
            double pl = ((dc / 2.0 - dcintf / 2.0) / 2.0) / Math.Tan(sig_ / 2);
            double oal = ls + lpr;
            double lta = oal - pl;
            //点---------------------------------------------------------------------------------------------
            //第一部分
            //切削部分
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0, 0, oal + 5);
            Vector2 p1 = fun.Polar(p0, pi / 2, dcintf / 2.0 + (dc / 2.0 - dcintf / 2.0) / 2.0);
            Vector2 p2 = fun.mirrorpoint(p1, p0_1, p0_2);
            Vector2 p3 = fun.Polar(p1, sig_ / 2, pl / Math.Cos(sig_ / 2));
            Vector2 p4 = fun.Polar(p3, fun.CalAngle(p3, p1) + pi / 2, fun.CalDistance(p3, p1));
            Vector2 p5 = fun.Polar(p4, fun.CalAngle(p4, p3) + sig_, fun.CalDistance(p3, p1));
            Vector2 p6 = fun.Polar(p5, fun.CalAngle(p5, p4) + pi / 2, fun.CalDistance(p3, p1));
            Vector2 p7 = fun.Polar(p6, fun.CalAngle(p6, p5) + sig_, fun.CalDistance(p3, p1));
            Vector2 p8 = fun.mirrorpoint(p3, p0_1, p0_2);
            Vector2 p9 = fun.mirrorpoint(p7, p0_1, p0_2);
            Vector2 p10 = fun.Polar(p8, 0, lcf / 200.0);
            Vector2 p11_1 = fun.Polar(p2, 0, oal);
            Vector2 p11_2 = fun.Polar(p10, fun.CalAngle(p8, p2), oal);
            Vector2 p11 = fun.Inters(p10, p11_2, p2, p11_1);
            Vector2 p12_1 = fun.Polar(p0, pi / 2, dcintf / 4.0);
            Vector2 p12_2 = fun.Polar(p12_1, 0, oal);
            Vector2 p12_3 = fun.Polar(p11, fun.CalAngle(p2, p9), oal);
            Vector2 p12 = fun.Inters(p11, p12_3, p12_1, p12_2);
            Vector2 p13_0 = fun.Polar(p12, fun.CalAngle(p7, p1), oal);
            Vector2 p13 = fun.Inters(p12, p13_0, p7, p6);
            Vector2 p14 = fun.Polar(p11, fun.CalAngle(p13, p6), fun.CalDistance(p13, p6) / 2.0);
            Vector2 p15 = fun.Polar(p8, 0, lcf / 6.0);
            Vector2 p16_1 = fun.Polar(p15, pi / 2, oal);
            Vector2 p16_2 = fun.Polar(fun.Polar(p7, pi / -2, fun.CalDistance(p7, p12) / 2.0), 0, oal);
            Vector2 p16 = fun.Inters(p7, p16_2, p16_1, p15);
            Vector2 arc1_1 = fun.Polar(fun.Polar(p7, pi / -2, fun.CalDistance(p7, p12) / 2.0), pi / -2, 0.1 * scale);
            Vector2 arc1_2 = fun.Polar(arc1_1, 0, oal);
            Arc arc1 = fun.DrawArc5(p12, new Line(arc1_1, arc1_2), p16);
            Vector2 p17_0 = fun.Polar(p14, pi / 2 - 10 * pi / 180, oal);
            Vector2 p17 = fun.Inters1(p14, p17_0, arc1, 0);
            Vector2 arc2_1 = fun.Polar(p17, 0, 0.01 * scale);
            Vector2 arc2_2 = fun.Polar(arc2_1, pi / -2 + 0.001 * pi / 180, oal);
            Arc arc2 = fun.DrawArc5(p14, new Line(arc2_1, arc2_2), p17);
            Vector2 p18_0 = fun.Polar(p9, 0, oal);
            Vector2 p18 = fun.Inters(p9, p18_0, p12, p11);
            Vector2 p19 = fun.Polar(p3, fun.CalAngle(p3, p4), fun.CalDistance(p3, p4) / 3.0);
            Vector2 p20_0 = fun.Polar(p19, 0, oal);
            Vector2 p20 = fun.Inters(p19, p20_0, p15, p16_1);
            Vector2 p21 = fun.Polar(p15, pi / 4, dc / 20.0);
            Vector2 p22 = fun.Polar(p20, pi / -4, fun.CalDistance(p15, p21));
            Vector2 p23 = new Vector2(lpr, 0);
            Vector2 p24 = fun.Polar(p23, pi / 2, df / 2.0);
            Vector2 p25 = fun.mirrorpoint(p24, p0_1, p0_2);
            Vector2 p26 = fun.Polar(p24, pi, lpr * (5.25 / 125.4));
            Vector2 p27 = fun.mirrorpoint(p26, p0_1, p0_2);
            Vector2 p28_0 = new Vector2(lcf, 0);
            Vector2 p28 = new Vector2(lcf, p26.Y - (p26.X - p28_0.X));
            Vector2 p29 = fun.mirrorpoint(p28, p0_1, p0_2);
            Vector2 arc3_1 = fun.Polar(p14, 0, 0.01 * scale);
            Vector2 arc3_2 = fun.Polar(arc3_1, pi / -2, oal);
            Arc arc3 = fun.DrawArc5(p10, new Line(arc3_2, arc3_1), p14);
            Vector2 arc4_1 = fun.Polar(p28, pi / 2, 0.01 * scale);
            Vector2 arc4_2 = fun.Polar(arc4_1, pi, oal);
            Arc arc4 = fun.DrawArc5(p28, new Line(arc4_1, arc4_2), p16);
            Vector2 p30_0 = fun.Polar(p22, -1 * pi / 180, oal);
            Vector2 p30 = fun.Inters1(p22, p30_0, arc4, 0);
            Vector2 arc5_1 = fun.Polar(p22, pi / 2, 0.01 * scale);
            Vector2 arc5_2 = fun.Polar(arc5_1, 0, oal);
            Arc arc5 = fun.DrawArc5(p30, new Line(arc5_1, arc5_2), p22);
            Vector2 p31_1 = fun.Polar(p22, pi / -4, oal);
            Vector2 p31 = fun.Inters1(p22, p31_1, arc4, 0);
            Vector2 arc6_1 = fun.Polar(p22, pi + pi / 4, 0.1 * scale);
            Vector2 arc6_2 = fun.Polar(arc6_1, pi / -4, oal);
            Arc arc6 = fun.DrawArc5(p22, new Line(arc6_1, arc6_2), p31);
            Vector2 p32_0 = fun.Polar(p14, 0, oal);
            Vector2 p32 = fun.Polar(p14, 0, lu);
            Vector2 arc7_1 = fun.Polar(p29, 0, 0.1 * scale);
            Vector2 arc7_2 = fun.Polar(arc7_1, 125 * pi / 180, oal);
            Arc arc7 = fun.DrawArc5(p29, new Line(arc7_1, arc7_2), p32);
            Vector2 arc8_1 = fun.Polar(p21, pi / -2, 0.1 * scale);
            Vector2 arc8_2 = fun.Polar(arc8_1, 0, oal);
            Arc arc8 = fun.DrawArc5(p21, new Line(arc8_1, arc8_2), p32);
            Vector2 p33_0 = fun.Polar(p28, 0, oal);
            Vector2 p33 = fun.Inters(p28, p33_0, p26, p27);
            Vector2 p34 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p35 = fun.Inters(p28, p33_0, p24, p25);
            Vector2 p36 = fun.mirrorpoint(p35, p0_1, p0_2);
            Vector2 arc9_1 = fun.Polar(p28, 0, (p26.X - p28.X) / 3.0);
            Vector2 arc9_2 = fun.Polar(arc9_1, pi / -2 + 0.01 * pi / 180, oal);
            Arc arc9 = fun.DrawArc5(p33, new Line(arc9_1, arc9_2), p34);
            Vector2 p37_0 = fun.Polar(p29, pi - 10 * pi / 180, oal);
            Vector2 p37 = fun.Inters1(p29, p37_0, arc8, 1);
            //非切削部分
            Vector2 p38 = fun.Polar(p0, 0, oal);
            Vector2 p39 = fun.Polar(p38, pi / 2, dconms / 2.0 - dconms / 20.0);
            Vector2 p40 = fun.Polar(p39, pi - pi / 4, (dconms / 20.0) / Math.Sqrt(2));
            Vector2 p41 = fun.Polar(p40, pi, ls - (p39.X - p40.X) - ((dconms / 20.0) * 1.5));
            Vector2 p42 = fun.Polar(p41, pi / -2, (dconms / 30.0) / 2.0);
            Vector2 p43_0 = fun.Polar(p42, pi, oal);
            Vector2 p43 = fun.Inters(p24, p25, p42, p43_0);
            Vector2 p44 = fun.mirrorpoint(p39, p0_1, p0_2);
            Vector2 p45 = fun.mirrorpoint(p40, p0_1, p0_2);
            Vector2 p46 = fun.mirrorpoint(p41, p0_1, p0_2);
            Vector2 p47 = fun.mirrorpoint(p42, p0_1, p0_2);
            Vector2 p48 = fun.mirrorpoint(p43, p0_1, p0_2);
            var polyline1 = Pus.AddPointsToLwPolyLine(p13, p7, p1, p3, p19, p20, p22, p20, p19, p4, p5, p6, p13, p12, p11,
            p14, p11, p10, p15, p21, p15, p16, p15, p10, p8, p2, p9, p18
            );
            var polyline2 = Pus.AddPointsToLwPolyLine(p28, p26, p24, p35, p33, p26, p24, p25, p27, p34,p33,p34, p36, p25, p27, p29, p37);
            polyline2.Vertexes[0].Bulge = Math.Tan((pi / 2) / 4);
            polyline2.Vertexes[12].Bulge = Math.Tan((pi / 2) / 4);
            var polyline3 = Pus.AddPointsToLwPolyLine(p43, p42, p47, p42, p41, p40, p45, p40, p39, p44, p45, p46, p47, p48);
          /*  dxf.AddEntity(new EntityObject[] { polyline1 ,polyline2  ,polyline3  
            ,arc1 ,arc2 ,arc3 ,arc4,arc5,arc6 ,arc7,arc8,arc9
            });*/
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            fun.drawBArc(dxf, arc3, 0.5, contour);
            fun.drawBArc(dxf, arc4, 0.5, contour);
            fun.drawBArc(dxf, arc5, 0.5, contour);
            fun.drawBArc(dxf, arc6, 0.5, contour);
            fun.drawBArc(dxf, arc7, 0.5, contour);
            fun.drawBArc(dxf, arc8, 0.5, contour);
           
            //定义格式，根据路径导出

            //标注
            Vector2 v1 = fun.Inters(p3, p6, p1, p5);
            fun.dimrot1(dxf, p0, p32, 180, dc + p32.Y, 2, 1.2 * scale, 1.6 * scale, 0.9, "LU", "", "");
            fun.dimrot1(dxf, p0, p29, 180, dc * 1.5 + p29.Y, 2, 1.2 * scale, 1.6 * scale, 0.9, "LCF", "", "");
            fun.dimrot1(dxf, p0, p25, 180, dc * 2 + p25.Y, 2, 1.2 * scale, 1.6 * scale, 0.9, "LPR", "", "");
            fun.dimrot1(dxf, p44, p25, 180, dc * 2 + p25.Y + p44.Y / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "LS", "", "");
            fun.dimrot1(dxf, p44, p0, 180, dc * 2.5 + (p25.Y), 2, 1.2 * scale, 1.6 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, fun .Polar (p8,pi/2,0.001), p8, 90, dc * 1.5, 2, 1.2 * scale, 1.6 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p0, p3, 0, dc * 1.5 - p3.Y / 2.0, 2, 1.2 * scale, 1.6 * scale, 0.9, "PL", "", "");
            fun.dimrot1(dxf, p40, p45, -90, dc, 2, 1.2 * scale, 1.6 * scale, 0.9, "DCONMS", "", "");
            fun.jdbz2(dxf, new Line(p8, p2), new Line(p3, p1), dc, 1.2 * scale, 1.6 * scale, 0.9, "SIG", "", "");
            Line linev6 = new Line(p0_1, p0_2);
            linev6.Lineweight = Lineweight.W25;//Lineweight指线宽
            linev6.Layer = centre;//Layer指图层
            linev6.LinetypeScale = 5 * scale;//指线性比例
            linev6.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(linev6); //提取
            Circle circle1 = new Circle(v1, 1.7 * 0.5 * scale);
            Circle circle2 = new Circle(p14, 1.7 * 0.5 * scale);
            dxf.AddEntity(new EntityObject[] {circle1 ,circle2  });


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}